<template>
  <div class = 'addBox'>
    <el-form
      ref="formName"
      :model="roleDto"
      label-position="left"
      :rules="rules"
      label-width="80px"
    >
      <el-row>
        <el-col :span="11">
          <el-form-item :span="12" label="角色名称" prop="name">
            <el-input v-model="roleDto.name" />
          </el-form-item>
        </el-col>
        <el-col :span="11">
          <el-form-item label="角色代码" prop="code">
            <el-input v-model="roleDto.code" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="角色备注" prop="remark">
            <el-input v-model="roleDto.remark" />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="11">
          <el-form-item label="是否启用">
            <el-radio-group v-model="roleDto.status">
              <el-radio  :label="1">是</el-radio>
              <el-radio  :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button id="btnCancel" @click="cancel">取 消</el-button>
      <el-button
        id="btnOK"
        type="primary"
        @click="confirm"
      >确 定</el-button>
      <!-- :disabled= "this.$store.state.user.judge" -->
    </span>
  </div>
</template>
<script>
export default {
  created() {
  },
  destroyed() {
    window.removeEventListener('load', e => this.cancel)
  },
  mounted() {
    window.addEventListener("load", () => {
      this.$router.push({
        path:'/centre/permission-manager/role',
      })
    });
  },
  watch: {
    $route: {
      handler: function(val, oldVal) {
        if (oldVal.path === '/centre/permission-manager/role/addRoleRouterIndex_testV1'){
          this.cancel()
        }
      },
      // 深度观察监听
      deep: true
    },
  },
  name: 'addRoleRouterIndex_testV1',
  data(){
    return{
      roleDto:{
        name: '',
        code: '',
        remark: '',
        id: '',
        status: '',
        version: '',
        created_by: '',
        companyId: '',
        tenantId: '',
        orgId: ''
      },
      rules: {
        name: [
          { required: true, message: '角色名称不能为空', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '角色编号不能为空', trigger: 'blur' }
        ],
        remark: [{ required: false, message: '备注不能为空', trigger: 'blur' }],
        companyId: [
          { required: true, message: '所属公司不能为空', trigger: 'change' }
        ]
      },
    }
  },
  methods:{
    confirm(){
      this.$refs.formName.validate((valid) => {
        if (valid) {
          this.$router.push({
            path:'/centre/permission-manager/role',
            query: {
              params: JSON.stringify(this.roleDto)
            }
          })
        }
      })
    },
    cancel(){
      this.$router.push({
        path:'/centre/permission-manager/role',
      })
    }
  }
}
</script>

<style scoped>
.addBox{
  position:absolute;
  z-index:20000;
  background-color: rgb(235,239,237);
  top:8.5%;
  bottom: 7.35%;
  left: 10%;
  right: 10%;
}

</style>
